﻿using System;
using System.Data;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Globalization;
using System.Linq;
using EstateNuke.Data.Properties;

namespace EstateNuke.Data
{
    public partial class EstateNukeCore
    {
        #region Company Level

        #region Department

        /// <summary>
        /// </summary>
        /// <param name = "department"></param>
        public void SaveChanges(Department department)
        {
            if (department == null)
            {
                throw new ArgumentNullException("department");
            }
            try
            {
                department.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Department", department.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "department"></param>
        public void CancelChanges(Department department)
        {
            if (department == null)
            {
                throw new ArgumentNullException("department");
            }
            try
            {
                //department.InternalEmployees.ToList().ForEach(CancelChanges);
                CancelChangesCore(department);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Department", department.Id), ex);
            }
        }

        #endregion

        #region District

        /// <summary>
        /// </summary>
        /// <param name = "district"></param>
        public void SaveChanges(District district)
        {
            if (district == null)
            {
                throw new ArgumentNullException("district");
            }
            try
            {
                district.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "District", district.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "district"></param>
        public void CancelChanges(District district)
        {
            if (district == null)
            {
                throw new ArgumentNullException("district");
            }
            try
            {
                //district.InternalCustomers.ToList().ForEach(CancelChanges);
                CancelChangesCore(district);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "District", district.Id), ex);
            }
        }

        #endregion

        #region Project

        /// <summary>
        /// </summary>
        /// <param name = "project"></param>
        public void SaveChanges(Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            try
            {
                project.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Project", project.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "project"></param>
        public void CancelChanges(Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            try
            {
                //project.InternalBuildings.ToList().ForEach(CancelChanges);
                //project.InternalCustomers.ToList().ForEach(CancelChanges);
                //project.InternalEmployees.ToList().ForEach(CancelChanges);
                project.InternalProjectAlertTypeSettings.ToList().ForEach(CancelChanges);
                project.InternalProjectRoomTypes.ToList().ForEach(CancelChanges);
                project.InternalProjectUsers.ToList().ForEach(CancelChanges);
                CancelChangesCore(project);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Project", project.Id), ex);
            }
        }

        #endregion

        #region User

        /// <summary>
        /// </summary>
        /// <param name = "user"></param>
        public void SaveChanges(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            try
            {
                user.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "User", user.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "user"></param>
        public void CancelChanges(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            try
            {
                user.InternalProjectUsers.ToList().ForEach(CancelChanges);
                //user.InternalPlans.ToList().ForEach(CancelChanges);
                //user.InternalReports.ToList().ForEach(CancelChanges);
                //user.InternalReportReplies.ToList().ForEach(CancelChanges);
                //user.InternalCustomerCommunicationScheduledCallbackAlerts.ToList().ForEach(CancelChanges);
                //user.InternalSmallOrderExpiredAlerts.ToList().ForEach(CancelChanges);
                //user.InternalLargeOrderEngagedContractAlerts.ToList().ForEach(CancelChanges);
                //user.InternalContractReceiptScheduledAlerts.ToList().ForEach(CancelChanges);
                //user.InternalLeaseOrderEngagedContractAlerts.ToList().ForEach(CancelChanges);
                //user.InternalLeaseContractReceiptScheduledAlerts.ToList().ForEach(CancelChanges);
                CancelChangesCore(user);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "User", user.Id), ex);
            }
        }

        #endregion

        #endregion

        #region Project Level

        #region Building

        /// <summary>
        /// </summary>
        /// <param name = "building"></param>
        public void SaveChanges(Building building)
        {
            if (building == null)
            {
                throw new ArgumentNullException("building");
            }
            try
            {
                building.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Building", building.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "building"></param>
        public void CancelChanges(Building building)
        {
            if (building == null)
            {
                throw new ArgumentNullException("building");
            }
            try
            {
                building.InternalEntrances.ToList().ForEach(CancelChanges);
                building.InternalFloors.ToList().ForEach(CancelChanges);
                CancelChangesCore(building);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Building", building.Id), ex);
            }
        }

        #endregion

        #region Employee

        /// <summary>
        /// </summary>
        /// <param name = "employee"></param>
        public void SaveChanges(Employee employee)
        {
            if (employee == null)
            {
                throw new ArgumentNullException("employee");
            }
            try
            {
                employee.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Employee", employee.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "employee"></param>
        public void CancelChanges(Employee employee)
        {
            if (employee == null)
            {
                throw new ArgumentNullException("employee");
            }
            try
            {
                //employee.InternalCustomers.ToList().ForEach(CancelChanges);
                //employee.InternalAgreements.ToList().ForEach(CancelChanges);
                //employee.InternalLeaseAgreements.ToList().ForEach(CancelChanges);
                employee.InternalEmployeePlans.ToList().ForEach(CancelChanges);
                CancelChangesCore(employee);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Employee", employee.Id), ex);
            }
        }

        #endregion

        #region Customer

        /// <summary>
        /// </summary>
        /// <param name = "customer"></param>
        public void SaveChanges(Customer customer)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }
            try
            {
                customer.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Customer", customer.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "customer"></param>
        public void CancelChanges(Customer customer)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }
            try
            {
                customer.InternalCustomerCommunications.ToList().ForEach(CancelChanges);
                customer.InternalCustomerRequirements.ToList().ForEach(CancelChanges);
                customer.InternalCustomerLeaseRequirements.ToList().ForEach(CancelChanges);
                //customer.InternalAgreements.ToList().ForEach(CancelChanges);
                //customer.InternalLeaseAgreements.ToList().ForEach(CancelChanges);
                CancelChangesCore(customer);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Customer", customer.Id), ex);
            }
        }

        #endregion

        #region ProjectAlertTypeSetting

        /// <summary>
        /// </summary>
        /// <param name = "projectAlertTypeSetting"></param>
        public void SaveChanges(ProjectAlertTypeSetting projectAlertTypeSetting)
        {
            if (projectAlertTypeSetting == null)
            {
                throw new ArgumentNullException("projectAlertTypeSetting");
            }
            try
            {
                projectAlertTypeSetting.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "ProjectAlertTypeSetting", projectAlertTypeSetting.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "projectAlertTypeSetting"></param>
        public void CancelChanges(ProjectAlertTypeSetting projectAlertTypeSetting)
        {
            if (projectAlertTypeSetting == null)
            {
                throw new ArgumentNullException("projectAlertTypeSetting");
            }
            try
            {
                CancelChangesCore(projectAlertTypeSetting);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "ProjectAlertTypeSetting", projectAlertTypeSetting.Id), ex);
            }
        }

        #endregion

        #region ProjectRoomType

        /// <summary>
        /// </summary>
        /// <param name = "projectRoomType"></param>
        public void SaveChanges(ProjectRoomType projectRoomType)
        {
            if (projectRoomType == null)
            {
                throw new ArgumentNullException("projectRoomType");
            }
            try
            {
                projectRoomType.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "ProjectRoomType", projectRoomType.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "projectRoomType"></param>
        public void CancelChanges(ProjectRoomType projectRoomType)
        {
            if (projectRoomType == null)
            {
                throw new ArgumentNullException("projectRoomType");
            }
            try
            {
                CancelChangesCore(projectRoomType);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "ProjectRoomType", projectRoomType.Id), ex);
            }
        }

        #endregion

        #region ProjectUser

        /// <summary>
        /// </summary>
        /// <param name = "projectUser"></param>
        public void SaveChanges(ProjectUser projectUser)
        {
            if (projectUser == null)
            {
                throw new ArgumentNullException("projectUser");
            }
            try
            {
                projectUser.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "ProjectUser", projectUser.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "projectUser"></param>
        public void CancelChanges(ProjectUser projectUser)
        {
            if (projectUser == null)
            {
                throw new ArgumentNullException("projectUser");
            }
            try
            {
                CancelChangesCore(projectUser);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "ProjectUser", projectUser.Id), ex);
            }
        }

        #endregion

        #region Plan

        /// <summary>
        /// </summary>
        /// <param name = "plan"></param>
        public void SaveChanges(Plan plan)
        {
            if (plan == null)
            {
                throw new ArgumentNullException("plan");
            }
            try
            {
                plan.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Plan", plan.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "plan"></param>
        public void CancelChanges(Plan plan)
        {
            if (plan == null)
            {
                throw new ArgumentNullException("plan");
            }
            try
            {
                plan.InternalEmployeePlans.ToList().ForEach(CancelChanges);
                CancelChangesCore(plan);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Plan", plan.Id), ex);
            }
        }

        #endregion

        #region Report

        /// <summary>
        /// </summary>
        /// <param name = "report"></param>
        public void SaveChanges(Report report)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }
            try
            {
                report.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Report", report.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "report"></param>
        public void CancelChanges(Report report)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }
            try
            {
                report.InternalReportAttachments.ToList().ForEach(CancelChanges);
                report.InternalReportReplies.ToList().ForEach(CancelChanges);
                CancelChangesCore(report.NextPlan);
                CancelChangesCore(report);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Report", report.Id), ex);
            }
        }

        #endregion

        #endregion

        #region Building Level

        #region Entrance

        /// <summary>
        /// </summary>
        /// <param name = "entrance"></param>
        public void SaveChanges(Entrance entrance)
        {
            if (entrance == null)
            {
                throw new ArgumentNullException("entrance");
            }
            try
            {
                entrance.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Entrance", entrance.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "entrance"></param>
        public void CancelChanges(Entrance entrance)
        {
            if (entrance == null)
            {
                throw new ArgumentNullException("entrance");
            }
            try
            {
                entrance.InternalRooms.ToList().ForEach(CancelChanges);
                entrance.InternalProperties.ToList().ForEach(CancelChanges);
                CancelChangesCore(entrance);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Entrance", entrance.Id), ex);
            }
        }

        #endregion

        #region Floor

        /// <summary>
        /// </summary>
        /// <param name = "floor"></param>
        public void SaveChanges(Floor floor)
        {
            if (floor == null)
            {
                throw new ArgumentNullException("floor");
            }
            try
            {
                floor.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Floor", floor.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "floor"></param>
        public void CancelChanges(Floor floor)
        {
            if (floor == null)
            {
                throw new ArgumentNullException("floor");
            }
            try
            {
                floor.InternalRooms.ToList().ForEach(CancelChanges);
                floor.InternalProperties.ToList().ForEach(CancelChanges);
                CancelChangesCore(floor);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Floor", floor.Id), ex);
            }
        }

        #endregion

        #endregion

        #region Customer Level

        #region CustomerRequirement

        /// <summary>
        /// </summary>
        /// <param name = "customerRequirement"></param>
        public void SaveChanges(CustomerRequirement customerRequirement)
        {
            if (customerRequirement == null)
            {
                throw new ArgumentNullException("customerRequirement");
            }
            try
            {
                customerRequirement.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "CustomerRequirement", customerRequirement.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "customerRequirement"></param>
        public void CancelChanges(CustomerRequirement customerRequirement)
        {
            if (customerRequirement == null)
            {
                throw new ArgumentNullException("customerRequirement");
            }
            try
            {
                customerRequirement.InternalCustomerRequirementResistances.ToList().ForEach(CancelChanges);
                customerRequirement.InternalCustomerRequirementRoomTypes.ToList().ForEach(CancelChanges);
                CancelChangesCore(customerRequirement);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "CustomerRequirement", customerRequirement.Id), ex);
            }
        }

        #endregion

        #region CustomerLeaseRequirement

        /// <summary>
        /// </summary>
        /// <param name = "customerLeaseRequirement"></param>
        public void SaveChanges(CustomerLeaseRequirement customerLeaseRequirement)
        {
            if (customerLeaseRequirement == null)
            {
                throw new ArgumentNullException("customerLeaseRequirement");
            }
            try
            {
                customerLeaseRequirement.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "CustomerLeaseRequirement", customerLeaseRequirement.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "customerLeaseRequirement"></param>
        public void CancelChanges(CustomerLeaseRequirement customerLeaseRequirement)
        {
            if (customerLeaseRequirement == null)
            {
                throw new ArgumentNullException("customerLeaseRequirement");
            }
            try
            {
                customerLeaseRequirement.InternalCustomerLeaseRequirementFacilities.ToList().ForEach(CancelChanges);
                CancelChangesCore(customerLeaseRequirement);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "CustomerLeaseRequirement", customerLeaseRequirement.Id), ex);
            }
        }

        #endregion

        #region CustomerCommunication

        /// <summary>
        /// </summary>
        /// <param name = "customerCommunication"></param>
        public void SaveChanges(CustomerCommunication customerCommunication)
        {
            if (customerCommunication == null)
            {
                throw new ArgumentNullException("customerCommunication");
            }
            try
            {
                customerCommunication.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "CustomerCommunication", customerCommunication.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "customerCommunication"></param>
        public void CancelChanges(CustomerCommunication customerCommunication)
        {
            if (customerCommunication == null)
            {
                throw new ArgumentNullException("customerCommunication");
            }
            try
            {
                customerCommunication.InternalCustomerCommunicationScheduledCallbackAlerts.ToList().ForEach(CancelChanges);
                CancelChangesCore(customerCommunication);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "CustomerCommunication", customerCommunication.Id), ex);
            }
        }

        #endregion

        #endregion

        #region Plan Level

        #region EmployeePlan

        /// <summary>
        /// </summary>
        /// <param name = "employeePlan"></param>
        public void SaveChanges(EmployeePlan employeePlan)
        {
            if (employeePlan == null)
            {
                throw new ArgumentNullException("employeePlan");
            }
            try
            {
                employeePlan.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "EmployeePlan", employeePlan.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "employeePlan"></param>
        public void CancelChanges(EmployeePlan employeePlan)
        {
            if (employeePlan == null)
            {
                throw new ArgumentNullException("employeePlan");
            }
            try
            {
                CancelChangesCore(employeePlan);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "EmployeePlan", employeePlan.Id), ex);
            }
        }

        #endregion

        #endregion

        #region Report Level

        #region ReportAttachment

        /// <summary>
        /// </summary>
        /// <param name = "reportAttachment"></param>
        public void SaveChanges(ReportAttachment reportAttachment)
        {
            if (reportAttachment == null)
            {
                throw new ArgumentNullException("reportAttachment");
            }
            try
            {
                reportAttachment.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "ReportAttachment", reportAttachment.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "reportAttachment"></param>
        public void CancelChanges(ReportAttachment reportAttachment)
        {
            if (reportAttachment == null)
            {
                throw new ArgumentNullException("reportAttachment");
            }
            try
            {
                CancelChangesCore(reportAttachment);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "ReportAttachment", reportAttachment.Id), ex);
            }
        }

        #endregion

        #region ReportReply

        /// <summary>
        /// </summary>
        /// <param name = "reportReply"></param>
        public void SaveChanges(ReportReply reportReply)
        {
            if (reportReply == null)
            {
                throw new ArgumentNullException("reportReply");
            }
            try
            {
                reportReply.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "ReportReply", reportReply.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "reportReply"></param>
        public void CancelChanges(ReportReply reportReply)
        {
            if (reportReply == null)
            {
                throw new ArgumentNullException("reportReply");
            }
            try
            {
                CancelChangesCore(reportReply);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "ReportReply", reportReply.Id), ex);
            }
        }

        #endregion

        #endregion

        #region CustomerRequirement & CustomerLeaseRequirement Level

        #region CustomerRequirementResistance

        /// <summary>
        /// </summary>
        /// <param name = "customerRequirementResistance"></param>
        public void SaveChanges(CustomerRequirementResistance customerRequirementResistance)
        {
            if (customerRequirementResistance == null)
            {
                throw new ArgumentNullException("customerRequirementResistance");
            }
            try
            {
                customerRequirementResistance.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "CustomerRequirementResistance", customerRequirementResistance.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "customerRequirementResistance"></param>
        public void CancelChanges(CustomerRequirementResistance customerRequirementResistance)
        {
            if (customerRequirementResistance == null)
            {
                throw new ArgumentNullException("customerRequirementResistance");
            }
            try
            {
                CancelChangesCore(customerRequirementResistance);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "CustomerRequirementResistance", customerRequirementResistance.Id), ex);
            }
        }

        #endregion

        #region CustomerRequirementRoomType

        /// <summary>
        /// </summary>
        /// <param name = "customerRequirementRoomType"></param>
        public void SaveChanges(CustomerRequirementRoomType customerRequirementRoomType)
        {
            if (customerRequirementRoomType == null)
            {
                throw new ArgumentNullException("customerRequirementRoomType");
            }
            try
            {
                customerRequirementRoomType.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "CustomerRequirementRoomType", customerRequirementRoomType.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "customerRequirementRoomType"></param>
        public void CancelChanges(CustomerRequirementRoomType customerRequirementRoomType)
        {
            if (customerRequirementRoomType == null)
            {
                throw new ArgumentNullException("customerRequirementRoomType");
            }
            try
            {
                CancelChangesCore(customerRequirementRoomType);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "CustomerRequirementRoomType", customerRequirementRoomType.Id), ex);
            }
        }

        #endregion

        #region CustomerLeaseRequirementFacility

        /// <summary>
        /// </summary>
        /// <param name = "customerLeaseRequirementFacility"></param>
        public void SaveChanges(CustomerLeaseRequirementFacility customerLeaseRequirementFacility)
        {
            if (customerLeaseRequirementFacility == null)
            {
                throw new ArgumentNullException("customerLeaseRequirementFacility");
            }
            try
            {
                customerLeaseRequirementFacility.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "CustomerLeaseRequirementFacility", customerLeaseRequirementFacility.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "customerLeaseRequirementFacility"></param>
        public void CancelChanges(CustomerLeaseRequirementFacility customerLeaseRequirementFacility)
        {
            if (customerLeaseRequirementFacility == null)
            {
                throw new ArgumentNullException("customerLeaseRequirementFacility");
            }
            try
            {
                CancelChangesCore(customerLeaseRequirementFacility);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "CustomerLeaseRequirementFacility", customerLeaseRequirementFacility.Id), ex);
            }
        }

        #endregion

        #endregion

        #region Entrance & Floor Level

        #region Room

        /// <summary>
        /// </summary>
        /// <param name = "room"></param>
        public void SaveChanges(Room room)
        {
            if (room == null)
            {
                throw new ArgumentNullException("room");
            }
            try
            {
                room.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Room", room.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "room"></param>
        public void CancelChanges(Room room)
        {
            if (room == null)
            {
                throw new ArgumentNullException("room");
            }
            try
            {
                room.InternalRoomPictures.ToList().ForEach(CancelChanges);
                //room.InternalAgreements.ToList().ForEach(CancelChanges);
                CancelChangesCore(room);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Room", room.Id), ex);
            }
        }

        #endregion

        #region Property

        /// <summary>
        /// </summary>
        /// <param name = "property"></param>
        public void SaveChanges(Property property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }
            try
            {
                property.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Property", property.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "property"></param>
        public void CancelChanges(Property property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }
            try
            {
                property.InternalPropertyPictures.ToList().ForEach(CancelChanges);
                //property.InternalLeaseAgreements.ToList().ForEach(CancelChanges);
                CancelChangesCore(property);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Property", property.Id), ex);
            }
        }

        #endregion

        #endregion

        #region Room & Property Level

        #region RoomPicture

        /// <summary>
        /// </summary>
        /// <param name = "roomPicture"></param>
        public void SaveChanges(RoomPicture roomPicture)
        {
            if (roomPicture == null)
            {
                throw new ArgumentNullException("roomPicture");
            }
            try
            {
                roomPicture.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "RoomPicture", roomPicture.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "roomPicture"></param>
        public void CancelChanges(RoomPicture roomPicture)
        {
            if (roomPicture == null)
            {
                throw new ArgumentNullException("roomPicture");
            }
            try
            {
                CancelChangesCore(roomPicture);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "RoomPicture", roomPicture.Id), ex);
            }
        }

        #endregion

        #region PropertyPicture

        /// <summary>
        /// </summary>
        /// <param name = "propertyPicture"></param>
        public void SaveChanges(PropertyPicture propertyPicture)
        {
            if (propertyPicture == null)
            {
                throw new ArgumentNullException("propertyPicture");
            }
            try
            {
                propertyPicture.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "PropertyPicture", propertyPicture.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "propertyPicture"></param>
        public void CancelChanges(PropertyPicture propertyPicture)
        {
            if (propertyPicture == null)
            {
                throw new ArgumentNullException("propertyPicture");
            }
            try
            {
                CancelChangesCore(propertyPicture);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "PropertyPicture", propertyPicture.Id), ex);
            }
        }

        #endregion

        #region Agreement

        /// <summary>
        /// </summary>
        /// <param name = "agreement"></param>
        public void SaveChanges(Agreement agreement)
        {
            if (agreement == null)
            {
                throw new ArgumentNullException("agreement");
            }
            try
            {
                agreement.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Agreement", agreement.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "agreement"></param>
        public void CancelChanges(Agreement agreement)
        {
            if (agreement == null)
            {
                throw new ArgumentNullException("agreement");
            }
            try
            {
                agreement.InternalAgreementDealingReasons.ToList().ForEach(CancelChanges);
                agreement.InternalSmallOrders.ToList().ForEach(CancelChanges);
                agreement.InternalLargeOrders.ToList().ForEach(CancelChanges);
                agreement.InternalContracts.ToList().ForEach(CancelChanges);
                agreement.InternalCancellations.ToList().ForEach(CancelChanges);
                CancelChangesCore(agreement.Room);
                CancelChangesCore(agreement);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Agreement", agreement.Id), ex);
            }
        }

        #endregion

        #region LeaseAgreement

        /// <summary>
        /// </summary>
        /// <param name = "leaseAgreement"></param>
        public void SaveChanges(LeaseAgreement leaseAgreement)
        {
            if (leaseAgreement == null)
            {
                throw new ArgumentNullException("leaseAgreement");
            }
            try
            {
                leaseAgreement.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "LeaseAgreement", leaseAgreement.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "leaseAgreement"></param>
        public void CancelChanges(LeaseAgreement leaseAgreement)
        {
            if (leaseAgreement == null)
            {
                throw new ArgumentNullException("leaseAgreement");
            }
            try
            {
                leaseAgreement.InternalLeaseOrders.ToList().ForEach(CancelChanges);
                leaseAgreement.InternalLeaseContracts.ToList().ForEach(CancelChanges);
                leaseAgreement.InternalLeaseCancellations.ToList().ForEach(CancelChanges);
                CancelChangesCore(leaseAgreement.Property);
                CancelChangesCore(leaseAgreement);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "LeaseAgreement", leaseAgreement.Id), ex);
            }
        }

        #endregion

        #endregion

        #region Agreement & LeaseAgreement Level

        #region AgreementDealingReason

        /// <summary>
        /// </summary>
        /// <param name = "agreementDealingReason"></param>
        public void SaveChanges(AgreementDealingReason agreementDealingReason)
        {
            if (agreementDealingReason == null)
            {
                throw new ArgumentNullException("agreementDealingReason");
            }
            try
            {
                agreementDealingReason.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "AgreementDealingReason", agreementDealingReason.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "agreementDealingReason"></param>
        public void CancelChanges(AgreementDealingReason agreementDealingReason)
        {
            if (agreementDealingReason == null)
            {
                throw new ArgumentNullException("agreementDealingReason");
            }
            try
            {
                CancelChangesCore(agreementDealingReason);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "AgreementDealingReason", agreementDealingReason.Id), ex);
            }
        }

        #endregion

        #region SmallOrder

        /// <summary>
        /// </summary>
        /// <param name = "smallOrder"></param>
        public void SaveChanges(SmallOrder smallOrder)
        {
            if (smallOrder == null)
            {
                throw new ArgumentNullException("smallOrder");
            }
            try
            {
                smallOrder.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "SmallOrder", smallOrder.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "smallOrder"></param>
        public void CancelChanges(SmallOrder smallOrder)
        {
            if (smallOrder == null)
            {
                throw new ArgumentNullException("smallOrder");
            }
            try
            {
                smallOrder.InternalSmallOrderExpiredAlerts.ToList().ForEach(CancelChanges);
                CancelChangesCore(smallOrder);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "SmallOrder", smallOrder.Id), ex);
            }
        }

        #endregion

        #region LargeOrder

        /// <summary>
        /// </summary>
        /// <param name = "largeOrder"></param>
        public void SaveChanges(LargeOrder largeOrder)
        {
            if (largeOrder == null)
            {
                throw new ArgumentNullException("largeOrder");
            }
            try
            {
                largeOrder.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "LargeOrder", largeOrder.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "largeOrder"></param>
        public void CancelChanges(LargeOrder largeOrder)
        {
            if (largeOrder == null)
            {
                throw new ArgumentNullException("largeOrder");
            }
            try
            {
                largeOrder.InternalLargeOrderEngagedContractAlerts.ToList().ForEach(CancelChanges);
                CancelChangesCore(largeOrder);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "LargeOrder", largeOrder.Id), ex);
            }
        }

        #endregion

        #region Contract

        /// <summary>
        /// </summary>
        /// <param name = "contract"></param>
        public void SaveChanges(Contract contract)
        {
            if (contract == null)
            {
                throw new ArgumentNullException("contract");
            }
            try
            {
                contract.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Contract", contract.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "contract"></param>
        public void CancelChanges(Contract contract)
        {
            if (contract == null)
            {
                throw new ArgumentNullException("contract");
            }
            try
            {
                contract.InternalContractReceipts.ToList().ForEach(CancelChanges);
                CancelChangesCore(contract);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Contract", contract.Id), ex);
            }
        }

        #endregion

        #region Cancellation

        /// <summary>
        /// </summary>
        /// <param name = "cancellation"></param>
        public void SaveChanges(Cancellation cancellation)
        {
            if (cancellation == null)
            {
                throw new ArgumentNullException("cancellation");
            }
            try
            {
                cancellation.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Cancellation", cancellation.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "cancellation"></param>
        public void CancelChanges(Cancellation cancellation)
        {
            if (cancellation == null)
            {
                throw new ArgumentNullException("cancellation");
            }
            try
            {
                cancellation.InternalCancellationWithdrawalReasons.ToList().ForEach(CancelChanges);
                CancelChangesCore(cancellation);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Cancellation", cancellation.Id), ex);
            }
        }

        #endregion

        #region LeaseOrder

        /// <summary>
        /// </summary>
        /// <param name = "leaseOrder"></param>
        public void SaveChanges(LeaseOrder leaseOrder)
        {
            if (leaseOrder == null)
            {
                throw new ArgumentNullException("leaseOrder");
            }
            try
            {
                leaseOrder.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "LeaseOrder", leaseOrder.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "leaseOrder"></param>
        public void CancelChanges(LeaseOrder leaseOrder)
        {
            if (leaseOrder == null)
            {
                throw new ArgumentNullException("leaseOrder");
            }
            try
            {
                leaseOrder.InternalLeaseOrderFacilities.ToList().ForEach(CancelChanges);
                leaseOrder.InternalLeaseOrderEngagedContractAlerts.ToList().ForEach(CancelChanges);
                CancelChangesCore(leaseOrder);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "LeaseOrder", leaseOrder.Id), ex);
            }
        }

        #endregion

        #region LeaseContract

        /// <summary>
        /// </summary>
        /// <param name = "leaseContract"></param>
        public void SaveChanges(LeaseContract leaseContract)
        {
            if (leaseContract == null)
            {
                throw new ArgumentNullException("leaseContract");
            }
            try
            {
                leaseContract.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "LeaseContract", leaseContract.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "leaseContract"></param>
        public void CancelChanges(LeaseContract leaseContract)
        {
            if (leaseContract == null)
            {
                throw new ArgumentNullException("leaseContract");
            }
            try
            {
                leaseContract.InternalLeaseContractReceipts.ToList().ForEach(CancelChanges);
                CancelChangesCore(leaseContract);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "LeaseContract", leaseContract.Id), ex);
            }
        }

        #endregion

        #region LeaseCancellation

        /// <summary>
        /// </summary>
        /// <param name = "leaseCancellation"></param>
        public void SaveChanges(LeaseCancellation leaseCancellation)
        {
            if (leaseCancellation == null)
            {
                throw new ArgumentNullException("leaseCancellation");
            }
            try
            {
                leaseCancellation.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "LeaseCancellation", leaseCancellation.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "leaseCancellation"></param>
        public void CancelChanges(LeaseCancellation leaseCancellation)
        {
            if (leaseCancellation == null)
            {
                throw new ArgumentNullException("leaseCancellation");
            }
            try
            {
                leaseCancellation.InternalLeaseCancellationWithdrawalReasons.ToList().ForEach(CancelChanges);
                CancelChangesCore(leaseCancellation);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "LeaseCancellation", leaseCancellation.Id), ex);
            }
        }

        #endregion

        #endregion

        #region Contract & Cancellation & LeaseOrder & LeaseContract & LeaseCancellation Level

        #region ContractReceipt

        /// <summary>
        /// </summary>
        /// <param name = "contractReceipt"></param>
        public void SaveChanges(ContractReceipt contractReceipt)
        {
            if (contractReceipt == null)
            {
                throw new ArgumentNullException("contractReceipt");
            }
            try
            {
                contractReceipt.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "ContractReceipt", contractReceipt.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "contractReceipt"></param>
        public void CancelChanges(ContractReceipt contractReceipt)
        {
            if (contractReceipt == null)
            {
                throw new ArgumentNullException("contractReceipt");
            }
            try
            {
                contractReceipt.InternalContractReceivedReceipts.ToList().ForEach(CancelChanges);
                contractReceipt.InternalContractReceiptScheduledAlerts.ToList().ForEach(CancelChanges);
                CancelChangesCore(contractReceipt);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "ContractReceipt", contractReceipt.Id), ex);
            }
        }

        #endregion

        #region ContractReceivedReceipt

        /// <summary>
        /// </summary>
        /// <param name = "contractReceivedReceipt"></param>
        public void SaveChanges(ContractReceivedReceipt contractReceivedReceipt)
        {
            if (contractReceivedReceipt == null)
            {
                throw new ArgumentNullException("contractReceivedReceipt");
            }
            try
            {
                contractReceivedReceipt.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "ContractReceivedReceipt", contractReceivedReceipt.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "contractReceivedReceipt"></param>
        public void CancelChanges(ContractReceivedReceipt contractReceivedReceipt)
        {
            if (contractReceivedReceipt == null)
            {
                throw new ArgumentNullException("contractReceivedReceipt");
            }
            try
            {
                CancelChangesCore(contractReceivedReceipt);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "ContractReceivedReceipt", contractReceivedReceipt.Id), ex);
            }
        }

        #endregion

        #region CancellationWithdrawalReason

        /// <summary>
        /// </summary>
        /// <param name = "cancellationWithdrawalReason"></param>
        public void SaveChanges(CancellationWithdrawalReason cancellationWithdrawalReason)
        {
            if (cancellationWithdrawalReason == null)
            {
                throw new ArgumentNullException("cancellationWithdrawalReason");
            }
            try
            {
                cancellationWithdrawalReason.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "CancellationWithdrawalReason", cancellationWithdrawalReason.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "cancellationWithdrawalReason"></param>
        public void CancelChanges(CancellationWithdrawalReason cancellationWithdrawalReason)
        {
            if (cancellationWithdrawalReason == null)
            {
                throw new ArgumentNullException("cancellationWithdrawalReason");
            }
            try
            {
                CancelChangesCore(cancellationWithdrawalReason);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "CancellationWithdrawalReason", cancellationWithdrawalReason.Id), ex);
            }
        }

        #endregion

        #region LeaseOrderFacility

        /// <summary>
        /// </summary>
        /// <param name = "leaseOrderFacility"></param>
        public void SaveChanges(LeaseOrderFacility leaseOrderFacility)
        {
            if (leaseOrderFacility == null)
            {
                throw new ArgumentNullException("leaseOrderFacility");
            }
            try
            {
                leaseOrderFacility.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "LeaseOrderFacility", leaseOrderFacility.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "leaseOrderFacility"></param>
        public void CancelChanges(LeaseOrderFacility leaseOrderFacility)
        {
            if (leaseOrderFacility == null)
            {
                throw new ArgumentNullException("leaseOrderFacility");
            }
            try
            {
                CancelChangesCore(leaseOrderFacility);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "LeaseOrderFacility", leaseOrderFacility.Id), ex);
            }
        }

        #endregion

        #region LeaseContractReceipt

        /// <summary>
        /// </summary>
        /// <param name = "leaseContractReceipt"></param>
        public void SaveChanges(LeaseContractReceipt leaseContractReceipt)
        {
            if (leaseContractReceipt == null)
            {
                throw new ArgumentNullException("leaseContractReceipt");
            }
            try
            {
                leaseContractReceipt.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "LeaseContractReceipt", leaseContractReceipt.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "leaseContractReceipt"></param>
        public void CancelChanges(LeaseContractReceipt leaseContractReceipt)
        {
            if (leaseContractReceipt == null)
            {
                throw new ArgumentNullException("leaseContractReceipt");
            }
            try
            {
                leaseContractReceipt.InternalLeaseContractReceiptScheduledAlerts.ToList().ForEach(CancelChanges);
                CancelChangesCore(leaseContractReceipt);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "LeaseContractReceipt", leaseContractReceipt.Id), ex);
            }
        }

        #endregion

        #region LeaseCancellationWithdrawalReason

        /// <summary>
        /// </summary>
        /// <param name = "leaseCancellationWithdrawalReason"></param>
        public void SaveChanges(LeaseCancellationWithdrawalReason leaseCancellationWithdrawalReason)
        {
            if (leaseCancellationWithdrawalReason == null)
            {
                throw new ArgumentNullException("leaseCancellationWithdrawalReason");
            }
            try
            {
                leaseCancellationWithdrawalReason.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "LeaseCancellationWithdrawalReason", leaseCancellationWithdrawalReason.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "leaseCancellationWithdrawalReason"></param>
        public void CancelChanges(LeaseCancellationWithdrawalReason leaseCancellationWithdrawalReason)
        {
            if (leaseCancellationWithdrawalReason == null)
            {
                throw new ArgumentNullException("leaseCancellationWithdrawalReason");
            }
            try
            {
                CancelChangesCore(leaseCancellationWithdrawalReason);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "LeaseCancellationWithdrawalReason", leaseCancellationWithdrawalReason.Id), ex);
            }
        }

        #endregion

        #endregion

        #region Alert Level

        #region CustomerCommunicationScheduledCallbackAlert

        /// <summary>
        /// </summary>
        /// <param name = "customerCommunicationScheduledCallbackAlert"></param>
        public void SaveChanges(CustomerCommunicationScheduledCallbackAlert customerCommunicationScheduledCallbackAlert)
        {
            if (customerCommunicationScheduledCallbackAlert == null)
            {
                throw new ArgumentNullException("customerCommunicationScheduledCallbackAlert");
            }
            try
            {
                customerCommunicationScheduledCallbackAlert.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "CustomerCommunicationScheduledCallbackAlert", customerCommunicationScheduledCallbackAlert.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "customerCommunicationScheduledCallbackAlert"></param>
        public void CancelChanges(CustomerCommunicationScheduledCallbackAlert customerCommunicationScheduledCallbackAlert)
        {
            if (customerCommunicationScheduledCallbackAlert == null)
            {
                throw new ArgumentNullException("customerCommunicationScheduledCallbackAlert");
            }
            try
            {
                CancelChangesCore(customerCommunicationScheduledCallbackAlert);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "CustomerCommunicationScheduledCallbackAlert", customerCommunicationScheduledCallbackAlert.Id), ex);
            }
        }

        #endregion

        #region SmallOrderExpiredAlert

        /// <summary>
        /// </summary>
        /// <param name = "smallOrderExpiredAlert"></param>
        public void SaveChanges(SmallOrderExpiredAlert smallOrderExpiredAlert)
        {
            if (smallOrderExpiredAlert == null)
            {
                throw new ArgumentNullException("smallOrderExpiredAlert");
            }
            try
            {
                smallOrderExpiredAlert.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "SmallOrderExpiredAlert", smallOrderExpiredAlert.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "smallOrderExpiredAlert"></param>
        public void CancelChanges(SmallOrderExpiredAlert smallOrderExpiredAlert)
        {
            if (smallOrderExpiredAlert == null)
            {
                throw new ArgumentNullException("smallOrderExpiredAlert");
            }
            try
            {
                CancelChangesCore(smallOrderExpiredAlert);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "SmallOrderExpiredAlert", smallOrderExpiredAlert.Id), ex);
            }
        }

        #endregion

        #region LargeOrderEngagedContractAlert

        /// <summary>
        /// </summary>
        /// <param name = "largeOrderEngagedContractAlert"></param>
        public void SaveChanges(LargeOrderEngagedContractAlert largeOrderEngagedContractAlert)
        {
            if (largeOrderEngagedContractAlert == null)
            {
                throw new ArgumentNullException("largeOrderEngagedContractAlert");
            }
            try
            {
                largeOrderEngagedContractAlert.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "LargeOrderEngagedContractAlert", largeOrderEngagedContractAlert.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "largeOrderEngagedContractAlert"></param>
        public void CancelChanges(LargeOrderEngagedContractAlert largeOrderEngagedContractAlert)
        {
            if (largeOrderEngagedContractAlert == null)
            {
                throw new ArgumentNullException("largeOrderEngagedContractAlert");
            }
            try
            {
                CancelChangesCore(largeOrderEngagedContractAlert);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "LargeOrderEngagedContractAlert", largeOrderEngagedContractAlert.Id), ex);
            }
        }

        #endregion

        #region ContractReceiptScheduledAlert

        /// <summary>
        /// </summary>
        /// <param name = "contractReceiptScheduledAlert"></param>
        public void SaveChanges(ContractReceiptScheduledAlert contractReceiptScheduledAlert)
        {
            if (contractReceiptScheduledAlert == null)
            {
                throw new ArgumentNullException("contractReceiptScheduledAlert");
            }
            try
            {
                contractReceiptScheduledAlert.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "ContractReceiptScheduledAlert", contractReceiptScheduledAlert.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "contractReceiptScheduledAlert"></param>
        public void CancelChanges(ContractReceiptScheduledAlert contractReceiptScheduledAlert)
        {
            if (contractReceiptScheduledAlert == null)
            {
                throw new ArgumentNullException("contractReceiptScheduledAlert");
            }
            try
            {
                CancelChangesCore(contractReceiptScheduledAlert);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "ContractReceiptScheduledAlert", contractReceiptScheduledAlert.Id), ex);
            }
        }

        #endregion

        #region LeaseOrderEngagedContractAlert

        /// <summary>
        /// </summary>
        /// <param name = "leaseOrderEngagedContractAlert"></param>
        public void SaveChanges(LeaseOrderEngagedContractAlert leaseOrderEngagedContractAlert)
        {
            if (leaseOrderEngagedContractAlert == null)
            {
                throw new ArgumentNullException("leaseOrderEngagedContractAlert");
            }
            try
            {
                leaseOrderEngagedContractAlert.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "LeaseOrderEngagedContractAlert", leaseOrderEngagedContractAlert.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "leaseOrderEngagedContractAlert"></param>
        public void CancelChanges(LeaseOrderEngagedContractAlert leaseOrderEngagedContractAlert)
        {
            if (leaseOrderEngagedContractAlert == null)
            {
                throw new ArgumentNullException("leaseOrderEngagedContractAlert");
            }
            try
            {
                CancelChangesCore(leaseOrderEngagedContractAlert);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "LeaseOrderEngagedContractAlert", leaseOrderEngagedContractAlert.Id), ex);
            }
        }

        #endregion

        #region LeaseContractReceiptScheduledAlert

        /// <summary>
        /// </summary>
        /// <param name = "leaseContractReceiptScheduledAlert"></param>
        public void SaveChanges(LeaseContractReceiptScheduledAlert leaseContractReceiptScheduledAlert)
        {
            if (leaseContractReceiptScheduledAlert == null)
            {
                throw new ArgumentNullException("leaseContractReceiptScheduledAlert");
            }
            try
            {
                leaseContractReceiptScheduledAlert.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "LeaseContractReceiptScheduledAlert", leaseContractReceiptScheduledAlert.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "leaseContractReceiptScheduledAlert"></param>
        public void CancelChanges(LeaseContractReceiptScheduledAlert leaseContractReceiptScheduledAlert)
        {
            if (leaseContractReceiptScheduledAlert == null)
            {
                throw new ArgumentNullException("leaseContractReceiptScheduledAlert");
            }
            try
            {
                CancelChangesCore(leaseContractReceiptScheduledAlert);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "LeaseContractReceiptScheduledAlert", leaseContractReceiptScheduledAlert.Id), ex);
            }
        }

        #endregion

        #endregion

        #region Global Level

        #region DealingReason

        /// <summary>
        /// </summary>
        /// <param name = "dealingReason"></param>
        public void SaveChanges(DealingReason dealingReason)
        {
            if (dealingReason == null)
            {
                throw new ArgumentNullException("dealingReason");
            }
            try
            {
                dealingReason.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "DealingReason", dealingReason.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "dealingReason"></param>
        public void CancelChanges(DealingReason dealingReason)
        {
            if (dealingReason == null)
            {
                throw new ArgumentNullException("dealingReason");
            }
            try
            {
                CancelChangesCore(dealingReason);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "DealingReason", dealingReason.Id), ex);
            }
        }

        #endregion

        #region InformationSource

        /// <summary>
        /// </summary>
        /// <param name = "informationSource"></param>
        public void SaveChanges(InformationSource informationSource)
        {
            if (informationSource == null)
            {
                throw new ArgumentNullException("informationSource");
            }
            try
            {
                informationSource.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "InformationSource", informationSource.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "informationSource"></param>
        public void CancelChanges(InformationSource informationSource)
        {
            if (informationSource == null)
            {
                throw new ArgumentNullException("informationSource");
            }
            try
            {
                CancelChangesCore(informationSource);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "InformationSource", informationSource.Id), ex);
            }
        }

        #endregion

        #region Facility

        /// <summary>
        /// </summary>
        /// <param name = "facility"></param>
        public void SaveChanges(Facility facility)
        {
            if (facility == null)
            {
                throw new ArgumentNullException("facility");
            }
            try
            {
                facility.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Facility", facility.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "facility"></param>
        public void CancelChanges(Facility facility)
        {
            if (facility == null)
            {
                throw new ArgumentNullException("facility");
            }
            try
            {
                CancelChangesCore(facility);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Facility", facility.Id), ex);
            }
        }

        #endregion

        #region Motivation

        /// <summary>
        /// </summary>
        /// <param name = "motivation"></param>
        public void SaveChanges(Motivation motivation)
        {
            if (motivation == null)
            {
                throw new ArgumentNullException("motivation");
            }
            try
            {
                motivation.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Motivation", motivation.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "motivation"></param>
        public void CancelChanges(Motivation motivation)
        {
            if (motivation == null)
            {
                throw new ArgumentNullException("motivation");
            }
            try
            {
                CancelChangesCore(motivation);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Motivation", motivation.Id), ex);
            }
        }

        #endregion

        #region Resistance

        /// <summary>
        /// </summary>
        /// <param name = "resistance"></param>
        public void SaveChanges(Resistance resistance)
        {
            if (resistance == null)
            {
                throw new ArgumentNullException("resistance");
            }
            try
            {
                resistance.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "Resistance", resistance.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "resistance"></param>
        public void CancelChanges(Resistance resistance)
        {
            if (resistance == null)
            {
                throw new ArgumentNullException("resistance");
            }
            try
            {
                CancelChangesCore(resistance);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "Resistance", resistance.Id), ex);
            }
        }

        #endregion

        #region RoomType

        /// <summary>
        /// </summary>
        /// <param name = "roomType"></param>
        public void SaveChanges(RoomType roomType)
        {
            if (roomType == null)
            {
                throw new ArgumentNullException("roomType");
            }
            try
            {
                roomType.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "RoomType", roomType.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "roomType"></param>
        public void CancelChanges(RoomType roomType)
        {
            if (roomType == null)
            {
                throw new ArgumentNullException("roomType");
            }
            try
            {
                roomType.InternalProjectRoomTypes.ToList().ForEach(CancelChanges);
                CancelChangesCore(roomType);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "RoomType", roomType.Id), ex);
            }
        }

        #endregion

        #region WithdrawalReason

        /// <summary>
        /// </summary>
        /// <param name = "withdrawalReason"></param>
        public void SaveChanges(WithdrawalReason withdrawalReason)
        {
            if (withdrawalReason == null)
            {
                throw new ArgumentNullException("withdrawalReason");
            }
            try
            {
                withdrawalReason.Ensure();
                SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.SaveChangesError, "WithdrawalReason", withdrawalReason.Id), ex);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name = "withdrawalReason"></param>
        public void CancelChanges(WithdrawalReason withdrawalReason)
        {
            if (withdrawalReason == null)
            {
                throw new ArgumentNullException("withdrawalReason");
            }
            try
            {
                CancelChangesCore(withdrawalReason);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CancelChangesError, "WithdrawalReason", withdrawalReason.Id), ex);
            }
        }

        #endregion

        #endregion

        #region Cancel Changes

        private void CancelChangesCore(EntityObject entity)
        {
            if (entity != null)
            {
                switch (entity.EntityState)
                {
                    case EntityState.Deleted:
                    case EntityState.Modified:
                        Refresh(RefreshMode.StoreWins, entity);
                        break;
                    case EntityState.Added:
                        Detach(entity);
                        break;
                }
            }
        }

        #endregion
    }
}